package com.aek.common.core.serurity;

import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

import com.aek.common.core.serurity.model.AuthUser;
import com.aek.common.core.util.SpringWebUtil;

/**
 * Web 工具类
 *
 * @author zj@aek56.com
 */
public final class WebSecurityUtils
{
    
    private WebSecurityUtils()
    {
        throw new IllegalAccessError("Utility class");
    }
    
    /**
     * 获取当前登录者对象
     *
     * @param <T> the type parameter
     * @return the current user
     */
    @SuppressWarnings("unchecked")
    public static <T extends UserDetails> T getCurrentUser()
    {
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        //return (T) authentication.getPrincipal();
        
        AuthUser user = new AuthUser("1");
        user.setTenantId(1);
        return (T) user;
    }
    
    /**
     * <一句话功能简述>获取当前token
     * <功能详细描述>
     * @return [参数说明]
     * 
     * @return String [返回类型说明]
     * @exception throws [违例类型] [违例说明]
     * @see [类、类#方法、类#成员]
     */
    public static String getCurrentToken()
    {
        return SpringWebUtil.getRequest().getHeader("X-AEK56-Token");
    }
    
}
